package org.rsbot.gui;

import java.awt.Dimension;
import java.io.File;
import java.net.MalformedURLException;
import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;

import org.rsbot.log.TextAreaLogHandler;
import org.rsbot.util.GlobalConfiguration;

public class LogGUI extends JInternalFrame {

    private static final long serialVersionUID = 1L;
    private JScrollPane textScroll;
    private Dimension minSize = new Dimension(765, 503);

    @Override
    public void setTitle(String title) {
        if (title != null) {
            super.setTitle(title + " - " + GlobalConfiguration.NAME + " v"
                    + ((float) GlobalConfiguration.getVersion() / 100) + " Log");
        } else {
            super.setTitle(GlobalConfiguration.NAME + " v"
                    + ((float) GlobalConfiguration.getVersion() / 100) + " Log");
        }
    }

    public LogGUI() {
        try {
            setFrameIcon(new ImageIcon(GlobalConfiguration.RUNNING_FROM_JAR ? getClass().getResource(GlobalConfiguration.Paths.Resources.LOG) : new File(GlobalConfiguration.Paths.LOG).toURI().toURL()));
        } catch (final MalformedURLException e1) {
        }
        setTitle(null);
        setPreferredSize(minSize);
        textScroll = new JScrollPane(
                TextAreaLogHandler.TEXT_AREA,
                JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        textScroll.setBorder(null);
        textScroll.setVisible(true);
        add(textScroll);
        pack();
        setVisible(true);
    }
}
